<template>
  <div id="user">
    <bread-crumb module-name="用户及权限" module-link="/sys" feature-name="用户管理" feature-link="users"/>
    <Table :data="page.list" :columns="userTableColums" border></Table>
  <div style="margin: 10px;overflow: hidden">
    <div style="float: right;">
      <Page :total="page.totalPage" :current="page.currPage" ></Page>
    </div>
  </div>
  </div>
</template>

<script>
  import BreadCrumb from '../Breadcrumb.vue'
  export default {
    components: {BreadCrumb},
    name: 'users',
    data () {
      return {
        userTableColums: [
          {
            title: '用户名',
            key: 'username',
            render: (h, params) => {
              return h('div', [
                h('Icon', {
                  props: {
                    type: 'person'
                  }
                }),
                h('strong', params.row.username)
              ])
            }
          },
          {
            title: '邮箱',
            key: 'email'
          },
          {
            title: '联系电话',
            key: 'mobile'
          },
          {
            title: '状态',
            key: 'status',
            render: (h, params) => {
              return h('div', [
                h('Tag', {
                  props: {
                    color: 'green'
                  }
                }, params.row.status === 1 ? '已激活' : '未激活')
              ])
            }
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.editUser(params.row.userId)
                    }
                  }
                }, '编辑'),
                h('Button', {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      this.remove(params.index)
                    }
                  }
                }, '删除')
              ])
            }
          }
        ],
        page: {
          totalCount: 0,
          pageSize: 0,
          totalPage: 0,
          currPage: 0,
          list: []
        }
      }
    },
    mounted () {
      this.$http.get('/sys/user/list?page=1&limit=5&sidx=user_id&order=desc').then((response) => {
        console.log(response.data)
        console.log(response.data.code)
        this.$data.page = response.data.page
      })
    },
    methods: {
      editUser (userId) {
        this.$router.push({name: 'editUser', params: {userId: userId}})
      }
    }
  }
</script>
<style>
  .hideColumn {
    display: none;
  }
</style>
